//
//  NSURL+image.m
//  UITool
//
//  Created by 索晓晓 on 2021/9/3.
//

#import "NSURL+image.h"

@implementation NSURL (image)

#define BaseSourceHost @"https://qingshi-server.meilanhu.vip"

+ (instancetype)URLWithImagePath:(NSString *)imagePath {
    
    if (!imagePath || [imagePath length] == 0) {
        return nil;
    }
    
    NSURL *url = [NSURL URLWithString:imagePath];
    
    if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) {
        return url;
    }
    
    if ([[imagePath substringToIndex:1] isEqual:@"/"]) {
        
//        if ([imagePath hasPrefix:@"/upload"]) {
//            url = [NSURL URLWithString:[NSString stringWithFormat:@"%@storage/app%@",BaseSourceHost,imagePath]];
//
//        } else {
            url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseSourceHost,imagePath]];

//        }
        
    } else {
        
//        if ([imagePath hasPrefix:@"upload"]) {
//            url = [NSURL URLWithString:[NSString stringWithFormat:@"%@storage/app/%@",BaseSourceHost,imagePath]];
//
//        } else {
            url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",BaseSourceHost,imagePath]];
//        }
    }
    NSLog(@"%@",url);
    return url;
}

@end
